// Common setup for robustness check simulations
// Author Levi Marks levi.marks.1>at>gmail.com

// Recovering parameters
mat coef = e(b)
mat fp_pwr =  e(fp_fp)
scalar beta_1 = coef[1,1]
scalar constant = coef[1,`=colsof(coef)']
scalar fp_1 = fp_pwr[1,1]
if dimension == 2 {
	scalar fp_2 = fp_pwr[1,2]
	scalar beta_2 = coef[1,2]
}

collapse (mean) rate gas p_spot, by(facility_id)

egen total_gas = sum(gas) // Total gas in sample
replace gas = gas*(32592000000/total_gas) // Scaling up gas production based on EIA 2016 estimate (from EIA March 2020 Monthly Energy Report)
gen emissions = rate*gas
sum emissions
scalar total_emissions = r(sum)
scalar total_emissions_tco2e = total_emissions*34/53.68

egen lower_bound = min(rate)
order lower_bound, after(facility_id)
rename rate rate_0
rename gas gas_0
rename p_spot price_0
gen emissions_0 = rate_0*gas_0
gen ag_cost_0 = 0
gen ag_reduction_0 = 0
gen ag_value_0 = 0
gen rate_00 = rate_0 // Reference so others can be deleted
gen price_00 = price_0 // Reference so others can be deleted
